package com.jixiang.phone.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.jixiang.phone.service.CodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

import static com.jixiang.common.constants.RedisConstants.REDIS_EXPIER_PHONE;
import static com.jixiang.common.constants.RedisConstants.REDIS_PREX_PHONE;
@Slf4j
@Component
public class CodeServiceImpl implements CodeService {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Override
    @Async("codeExecutor")
    public void sendCode(String code) {
        String numbers = RandomUtil.randomNumbers(6);
        stringRedisTemplate.opsForValue().set(REDIS_PREX_PHONE+code,numbers,REDIS_EXPIER_PHONE, TimeUnit.MINUTES);
        log.info(code+ "----->"+numbers);
    }
}
